# Contributor: omni <omni+alpine@hack.org>
# Maintainer: Paul Morgan <jumanjiman@gmail.com>
pkgname=editorconfig
_pkgname=$pkgname-core-c
pkgver=0.12.5
_testname=editorconfig-core-test
_testver=0.13
pkgrel=0
pkgdesc="core library written in C for use by plugins supporting EditorConfig parsing"
url="https://github.com/editorconfig/editorconfig-core-c"
arch="all"
license="BSD-2-Clause"
makedepends="cmake pcre2-dev"
subpackages="lib$pkgname:libs $pkgname-static $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/editorconfig/$_pkgname/archive/v$pkgver.tar.gz
	$_testname-$_testver.tar.gz::https://github.com/editorconfig/$_testname/archive/v$_testver.tar.gz
	use-compiled-binary.patch
	disable-failing-test.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	# Tests are taken from a github release tarball so place them in the tree
	rmdir tests
	mv ../"$_testname"-"$_testver" tests
	default_prepare
}

build() {
	cmake . \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_C_FLAGS_MINSIZEREL="$CFLAGS" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_DOCUMENTATION=False
	make
}

check() {
	make test
}

package() {
	make install DESTDIR="$pkgdir"

	# Remove symlink to editorconfig-$pkgver.
	rm -f "$pkgdir"/usr/bin/"$pkgname"
	mv -f "$pkgdir"/usr/bin/"$pkgname"-"$pkgver" "$pkgdir"/usr/bin/"$pkgname"
}

static() {
	depends=""
	pkgdesc="$pkgdesc (static library)"
	mkdir -p "$subpkgdir"/usr/lib
	mv "$pkgdir"/usr/lib/*.a "$subpkgdir"/usr/lib
}

sha512sums="
7d54c8c1ade8ecef5dc8f35e006f0e226455b7ed9541442a846bbebc26765e92abbbb29b991748164015bcfaff8764a0ac007e4384e163678a2922f7ca6b2e03  editorconfig-0.12.5.tar.gz
655da56c688e06ec0fb6fee06c89ad2eeef7be48ec2df861ed5ce20417801b4fe8ddf2df31026a8b2fb35fe1ab96daadedceb34f4d3231f931c30f109a5d894b  editorconfig-core-test-0.13.tar.gz
52c969479e62f8cd3fe751cb3421dc06cf39e50eaf7dfd39626cbbdaaa46ec51d348f1a5f4908300855bcebd32760cb4995f2861c2010d5d76a2063be9aea761  use-compiled-binary.patch
fa283b90a5aa6f64e02963c861456968614dc8cac367bb7583a0d511050ac5339f16d94a0fb47386f197c497a64fcb86ef2ae0c5e8c3111e38b4aeb0880d737d  disable-failing-test.patch
"
